//https://leetcode.cn/problems/binary-tree-level-order-traversal-ii/
class Solution {
public:
    vector<vector<int>> levelOrderBottom(TreeNode* root) {
        queue<TreeNode*> qt;
        vector<vector<int>> ret;
        if (root == nullptr)
        {
            return ret;
        }
        list<vector<int>> lv;

        qt.push(root);
        while (!qt.empty())
        {
            int len = qt.size();
            vector<int> tmp;
            for (int i = 0; i < len; ++i)
            {
                TreeNode* front = qt.front();
                qt.pop();
                tmp.push_back(front->val);

                if (front->left)
                    qt.push(front->left);
                if (front->right)
                    qt.push(front->right);
            }
            lv.push_front(tmp);
        }
        for (auto l : lv)
        {
            ret.push_back(l);
        }

        return ret;
    }
};